package com.example.game.sdk.channel.real

import android.app.Activity
import android.app.AlertDialog
import android.content.DialogInterface
import android.os.Bundle
import android.util.Log
import com.example.game.sdk.framework.GameApiCallback
import com.example.game.sdk.framework.plugin.channel.ChannelTemplate
import org.json.JSONObject

private const val TAG = "RealChannel"

/**
 *  我是一个假装的真实渠道，打包注入到游戏apk
 */
class RealChannel: ChannelTemplate() {

    override fun onCreate(activity: Activity, savedInstanceState: Bundle?) {
        super.onCreate(activity, savedInstanceState)
        Log.d(TAG,"onCreate")
    }

    override fun onResume(activity: Activity) {
        super.onResume(activity)
        Log.d(TAG,"onResume")

    }
    override fun init(params: JSONObject) {
        super.init(params)
        Log.d(TAG,"init")
    }

    override fun login(callback: GameApiCallback) {

        AlertDialog.Builder(activity)
            .setTitle("登录")
            .setMessage("欢迎使用GameSDK")
            .setNegativeButton("取消",object : DialogInterface.OnClickListener{
                override fun onClick(dialog: DialogInterface?, which: Int) {
                    callback.onResult(2,"cancel login", JSONObject())
                }
            })
            .setPositiveButton("登录",object : DialogInterface.OnClickListener{
                override fun onClick(dialog: DialogInterface?, which: Int) {
                    callback.onResult(1,"login success", JSONObject())
                }
            })
            .show()
    }

    override fun logout(callback: GameApiCallback) {
        callback.onResult(1,"logout success", JSONObject())
    }

    override fun pay(
        params: JSONObject,
        callback: GameApiCallback
    ) {
        AlertDialog.Builder(activity)
            .setTitle("支付")
            .setMessage("欢迎使用GameSDK")
            .setNegativeButton("取消",object : DialogInterface.OnClickListener{
                override fun onClick(dialog: DialogInterface?, which: Int) {
                    callback.onResult(2,"cancel login", JSONObject())
                }
            })
            .setPositiveButton("支付",object : DialogInterface.OnClickListener{
                override fun onClick(dialog: DialogInterface?, which: Int) {
                    callback.onResult(1,"login success", JSONObject())
                }
            })
            .show()
    }
}